import json
import random

from flask import Flask, render_template, Blueprint, redirect, request

from utils import get_stock_data, get_order_main_data, get_order_month_gmv_data, get_order_platform_data, \
    get_order_month_paynum_data, get_order_line2_data

app = Flask(__name__)


@app.route('/')
def index():
    return redirect('/static/index.html')


@app.route('/kline')
def kline():
    return redirect('/static/kline.html')


@app.route('/order')
def order():
    return redirect('/static/order.html')


@app.route('/api/general_data')
def get_general_data():
    return {'items': [
        {'icon': 'house.png', 'value': 16543, 'name': '省重点实验室数'},
        {'icon': 'computer.png', 'value': 9631, 'name': '全省科研项目数'},
        {'icon': 'medal.png', 'value': 36542, 'name': '全省科研成果数'},
        {'icon': 'professor.png', 'value': 13642, 'name': '科研专家数'},
        {'icon': 'equipment.png', 'value': 15536, 'name': '科研仪器经费'},
    ]}


@app.route('/api/kline_data')
def kline_data():
    start_date = request.args.get('start_date','2020-1-1')
    end_date = request.args.get('end_date','2020-3-1')
    data_x, data_y = get_stock_data(start_date, end_date)
    return {'data_x': data_x,'data_y':data_y}


@app.route('/api/order_main_data')
def order_main_data():
    return get_order_main_data()


@app.route('/api/order_month_gmv_data')
def order_month_gmv_data():
    return get_order_month_gmv_data()


@app.route('/api/order_platform_data')
def order_platform_data():
    return get_order_platform_data()


@app.route('/api/order_month_paynum_data')
def order_month_paynum_data():
    return get_order_month_paynum_data()


@app.route('/api/order_line2_data')
def order_line2_data():
    return get_order_line2_data()


if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)
